﻿/* Created by: Vinicios da Silva
 * Contact:  vinicios.dasilva@edu.sait.ca*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TravelExpertsManagementConsole
{
    public partial class formBooking : Form
    {
        public formBooking(frmContainer parent)
        {
            InitializeComponent();
            MdiParent = parent;
        }
        
        private void formBooking_Load(object sender, EventArgs e)
            {
                RefreshData();
            }

        public void RefreshData()
            {
                try 
                {
                    AccessBooking myDB = new AccessBooking();
                    bookingListBox.DataSource = myDB.Select();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
           }

        private void btnView_Click(object sender, EventArgs e)
        {
            if (bookingListBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please make sure you selected a book to look at!");
                return;
            }

            Booking getIt = new Booking();
            getIt = (Booking)bookingListBox.SelectedItem;

            tbStartDate.Text = getIt.TripStart.ToString();
            tbEndDate.Text = getIt.TripEnd.ToString();
            tbAgencyCom.Text = getIt.AgencyCommission.ToString();
            tbBasePrice.Text = getIt.BasePrice.ToString();
            tbDescription.Text = getIt.Description;
            tbDestination.Text = getIt.Destination;
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            frmContainer Parent = (frmContainer)MdiParent;
            if (Parent.childHomePage == null)
            {
                Parent.childHomePage = new Home(Parent);
                Parent.childHomePage.Show();
            }
            Parent.childHomePage.Focus();
        }

        private void formBooking_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmContainer parent = (frmContainer)MdiParent;

            parent.childBooking = null;
        }
    }
}
